//
//  EFBannerCell.m
//  EnjogFood
//
//  Created by 王芳 on 17/5/2.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFBannerCell.h"
#import "EFBannerItem.h"
#import "EFEventPromotionViewController.h"

@interface EFBannerCell ()
@property (strong, nonatomic) UIImageView *bannerImageV;
@property (strong, nonatomic) EFBannerItem *bannerItem;
@end

@implementation EFBannerCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.bannerImageV];
        self.bannerImageV.top = 20;
        self.backgroundColor = RGBCOLOR(0xf5f9f9);
    }
    return self;
}

- (void)setObject:(EFBannerItem *)item{
    self.bannerItem = item;
    if (item.img.length > 0) {
        [self.bannerImageV setImageWithURL:[NSURL URLWithString:item.img]];
        [self.bannerImageV addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(turnToEventPage)]];
    }
}

- (void)turnToEventPage{
    EFEventPromotionViewController *vc = [[EFEventPromotionViewController alloc] initWithEventId:[NSNumber numberWithInteger:self.bannerItem.id.integerValue]];
    [ICNavigator pushViewController:vc animated:YES];
}

- (UIImageView *)bannerImageV{
    if (!_bannerImageV) {
        _bannerImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 110)];
        _bannerImageV.backgroundColor = RGBCOLOR(0xf3f3f3);
        _bannerImageV.userInteractionEnabled = YES;
        _bannerImageV.contentMode = UIViewContentModeScaleAspectFill;
        _bannerImageV.clipsToBounds = YES;
    }
    return _bannerImageV;
}

@end
